package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.AccountApply;
import com.briup.jz.bean.AccountApplyExample;
import com.briup.jz.bean.AccountApplyExample.Criteria;
import com.briup.jz.dao.AccountApplyMapper;
import com.briup.jz.service.IJzAccountApplyService;
import com.briup.jz.utils.CustomerException;

@Service
public class JzAccountServiceImpl implements IJzAccountApplyService {
	
	@Autowired
	private AccountApplyMapper accountApplyMapper;
	
	@Override
	public void saveOrUpdate(AccountApply accountapply) {
		// TODO Auto-generated method stub
		if(accountapply.getId()!=null) {
			accountApplyMapper.updateByPrimaryKey(accountapply);
		} else {
			// 判断是否有同名的分类，如果有抛出异常
			accountApplyMapper.insert(accountapply);
		}
	}

	@Override
	public List<AccountApply> query(Double money) {
		// TODO Auto-generated method stub
		AccountApplyExample example = new AccountApplyExample();
		Criteria criteria = example.createCriteria();
		if(money != null)
		{
			criteria.andMoneyEqualTo(money);
		}
		return accountApplyMapper.selectByExample(example);
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		// TODO Auto-generated method stub
		AccountApply accountApply=accountApplyMapper.selectByPrimaryKey(id);
		if(accountApply==null )
		{
			throw new CustomerException("要删除的分类信息不存在");
		}
		accountApplyMapper.deleteByPrimaryKey(id);
	}

	


}
